package Hangman;

import java.io.File;
import java.io.IOException;

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;

class Beep implements Runnable{
	
	private String beepFile;
	private Thread thread;
	
	Beep(String _beepFile){
		thread= new Thread(this, "beepThread");
		beepFile= _beepFile;
		thread.start();
	}
	
	public void playSound() {
		try {
			AudioInputStream audio = AudioSystem.getAudioInputStream(new File(beepFile));
			Clip clip = AudioSystem.getClip();
			clip.open(audio);
			clip.start();
			while(clip.isRunning()){
				thread.sleep(500);
			}
		}

		catch (UnsupportedAudioFileException uae) {
			System.out.println(uae);
		} catch (IOException ioe) {
			System.out.println(ioe);
		} catch (LineUnavailableException lua) {
			System.out.println(lua);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Override
	public void run() {
		playSound();
	}
	
}

